<?php
namespace app\api\model;
use think\Model;
use think\model\concern\SoftDelete;
class EmployeeInformation extends Model
{
    use SoftDelete;
    protected $name = "employee_information";
    protected $pk = "id";
    protected $deleteTime = "delete_time";
    protected $defaultSoftDelete = 0;
    protected $json = [];
    protected $jsonAssoc = true;
    public function getCertificatesAttr($value){
        if($value){
            $value = getAppFilePath($value,true);
        }else{
            $value = [];
        }
        return $value;
    }
    public function getBirthDataAttr($value){
        if($value){
            $value = $this->birthdayToAge($value);
        }else{
            $value = '未知';
        }
        return $value;
    }
    protected function birthdayToAge($birthday){
        $age = strtotime($birthday);
        if($age === false){
            return false;
        }
        list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
        $now = strtotime("now");
        list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
        $age = $y2 - $y1;
        if((int)($m2.$d2) < (int)($m1.$d1))
            $age -= 1;
        return $age;
    }
}